﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace test._99_test.time._2012_02_09_113240
{
    public partial class Form5 : Form
    {
        public Form5()
        {
            InitializeComponent();
        }

        PictureBox p;
        PictureBox p1 = new PictureBox();
        System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();

        /// <summary>
        /// 准备写一个动画 点人人会跳 点鸟鸟飞上树梢 技术还是两个控件
        /// 需要三张图片 树 人 鸟
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form5_Load(object sender, EventArgs e)
        {
            this.Width = 800;
            this.Height = 600;

            //Bitmap newBitmap = new Bitmap(50, 50, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            //Graphics g = Graphics.FromImage(newBitmap);
            //g.FillRectangle(new SolidBrush(Color.Red), new Rectangle(0, 0, 50, 50));
            //newBitmap.Save(System.IO.Path.Combine (Environment.CurrentDirectoryEnvironment.CurrentDirectory,"1.png"), ImageFormat.Png);

            p = new PictureBox();
            p.Image = new Bitmap("img/ren.gif");
            p.Top = 150;
            p.Left = 10;

            p.Click += new EventHandler(ren_tiao);
            this.Controls.Add(p);

            p1.Image = new Bitmap("img/cao.gif");
            p1.Top = p.Top + p.Height;
            this.Controls.Add(p1);
        }

        private void ren_tiao(object sender, EventArgs e)
        {
            timer1.Tick += new System.EventHandler(this.timer1_Tick);
            timer1.Interval = 500; // 设置timer时间，单位是毫秒
            timer1.Enabled = true; // 启动 timer
        }

        bool flag = true;

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (flag)
            {
                p.Top -= 10;
            }

            if (p.Top == 100)
            {
                flag = false;
            }
            if (!flag)
            {
                p.Top += 10;
            }
            if (p.Top == 150 && !flag)
            {
                timer1.Enabled = false;
                flag = true;
            }
        }
    }
}